package com.link.base.base.accnt.service;

import com.link.base.base.accnt.dao.mybatis.mapper.QdAccountQdMapper;
import com.link.base.base.accnt.model.QdAccountQd;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.dao.siebel.mapper.BasicMapperSiebel;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/7 16:55
 * @version 1.0
 */

@Service
public class QdAccountQdServiceImpl extends BasicServiceImpl<QdAccountQd> implements QdAccountQdService {

    @Resource
    private QdAccountQdMapper qdAccountQdMapper;


    @Override
    public BasicMapper<QdAccountQd> getBasicMapper() {
        return null;
    }

    @Override
    public BasicMapperSiebel<QdAccountQd> getSiebelBasicMapper() throws Exception {

        return null;
    }

    /**
     * @author HuangLJ
     * @Description 删除客户和企点客户中间表信息
     * @Date 2017-06-21
     */
    @Override
    public void deleteAccountQd(QdAccountQd qdAccountQd) throws Exception {
        Long corpId = qdAccountQd.getCorpid();
        Long accountId = qdAccountQd.getAccountId();
        String qdAccountId = qdAccountQd.getQdAccountId();
        if (null != corpId && "".equals(qdAccountId) && null == accountId) {
            qdAccountQdMapper.deleteAccountQd(qdAccountQd);
        }
    }

    /**
     * @author HuangLJ
     * @Desctiption 插入客户，企点客户中间表
     * @Date 2017-06-21
     */
    @Override
    public void insert(QdAccountQd qdAccountQd) throws Exception {
        List list = qdAccountQdMapper.queryAll(qdAccountQd);
        Long accountId = qdAccountQd.getAccountId();
        String qdAccountId = qdAccountQd.getQdAccountId();
        Long corpId = qdAccountQd.getCorpid();
        boolean flagTwo = null == accountId && null == corpId && "".equals(qdAccountId);
        boolean flagOne = list != null && list.size() < 1;
        if (flagOne && !flagTwo) {
            // 如果当前记录总数小于1,则插入记录 否则不做操作
            qdAccountQd.setId(keyGenerateService.keyGenerate());
            qdAccountQdMapper.insertAccountQd(qdAccountQd);
        }
    }

    /**
     * 通过客户id和奇点客户id查询
     * @param qdAccountQd
     * @return
     * @throws Exception
     */
    @Override
    public QdAccountQd queryByAccntIdAndQdAccntId(QdAccountQd qdAccountQd) throws Exception {
        return qdAccountQdMapper.queryByAccntIdAndQdAccntId(qdAccountQd);
    }
}
